package com.deyuanyun.pic.settings.task;

import com.deyuanyun.pic.settings.service.msgtemplate.AbstractPushMsgTemplate;
import com.deyuanyun.pic.settings.service.msgtemplate.pbf.DefectNoticePushMsg;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;

/**
 *  缺陷通知任务调度
 *  @author axiao(xj08.dream@gmail.com)
 *  @date 2016-07-25
 *  @version 1.0
 *  Histroy: [修改人][时间][描述]
 */
public class DefectNoticeTask extends MethodInvokingJobDetailFactoryBean.StatefulMethodInvokingJob {

    private static final Logger LOGGER = LoggerFactory.getLogger(DefectNoticeTask.class);

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        try {
            if(LOGGER.isInfoEnabled()) {
                JobKey jobKey = context.getTrigger().getJobKey();
                LOGGER.info("得到需要执行的任务名为：" + jobKey.getName());
                LOGGER.info("得到需要执行的任务组名为："  + jobKey.getGroup());
                LOGGER.info("***缺陷通知任务调度开始执行***");
            }
            JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
            AbstractPushMsgTemplate pushMsgTemplate = new DefectNoticePushMsg();
            pushMsgTemplate.setInterface(false, jobDataMap);
            pushMsgTemplate.pushMsg();
            LOGGER.info("***缺陷通知任务调度执行结束***");
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
}
